#include "loginandregisterdialog.h"

#include <QPushbutton>

LoginAndRegisterDialog::LoginAndRegisterDialog(QWidget *parent)
    :QWidget(parent)
{

    layout=new QGridLayout();
    layout->setContentsMargins(30,40,30,30);
    layout->setVerticalSpacing(15);
    layout->setHorizontalSpacing(10);
    layout->setAlignment(Qt::AlignTop);
    this->setFixedSize(350,400);
    this->setWindowTitle("登录");
    this->setWindowIcon(QIcon(":/Resources/windowIcon.png"));
    this->setAttribute(Qt::WA_DeleteOnClose);
    this->setLayout(layout);
    // 设置窗口背景
    this->setStyleSheet(
        "QWidget {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:1,"
        "               stop:0 #1a1a2e, stop:0.5 #16213e, stop:1 #0d0d1a);"
        "   color: #e0e0e0;"
        "   font-family: 'Microsoft YaHei', sans-serif;"
        "}");

    title =new QLabel();
    title->setText("登录");
    title->setFixedHeight(60);
    title->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed);
    title->setAlignment(Qt::AlignCenter);
    title->setStyleSheet(
        "QLabel {"
        "   color: #ffd166;"
        "   font-size: 24px;"
        "   font-weight: bold;"
        "   background: transparent;"
        "   padding: 10px 0px;"
        "   margin-bottom: 10px;"
        "}");

    username=new QLineEdit();
    username->setPlaceholderText("🔤 输入用户名");
    username->setFixedHeight(45);
    username->setStyleSheet(
        "QLineEdit {"
        "   background: rgba(45, 45, 65, 0.8);"
        "   border: 2px solid rgba(255, 255, 255, 0.1);"
        "   border-radius: 22px;"
        "   color: #e0e0e0;"
        "   font-size: 14px;"
        "   padding: 0px 20px;"
        "   selection-background-color: rgba(255, 107, 107, 0.3);"
        "}"
        "QLineEdit:focus {"
        "   border: 2px solid rgba(255, 107, 107, 0.6);"
        "   background: rgba(55, 55, 75, 0.9);"
        "}"
        "QLineEdit::placeholder {"
        "   color: rgba(255, 255, 255, 0.5);"
        "   font-style: italic;"
        "}");

    password=new QLineEdit();
    password->setPlaceholderText("🔒 输入密码");
    password->setEchoMode(QLineEdit::Password);
    password->setFixedHeight(45);
    password->setStyleSheet(username->styleSheet());

    yanzhengcodeline=new QLineEdit();
    yanzhengcodeline->setPlaceholderText("📝 输入验证码");
    yanzhengcodeline->setFixedHeight(45);
    yanzhengcodeline->setStyleSheet(username->styleSheet());

    yanzhengcodelabel=new QLabel();
    yanzhengcodelabel->setText("验证码");
    yanzhengcodelabel->setAlignment(Qt::AlignCenter);
    yanzhengcodelabel->setFixedHeight(45);
    yanzhengcodelabel->setStyleSheet(
        "QLabel {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "               stop:0 #ff6b6b, stop:1 #06d6a0);"
        "   border: none;"
        "   border-radius: 15px;"
        "   color: white;"
        "   font-size: 12px;"
        "   font-weight: bold;"
        "   padding: 5px 10px;"
        "   margin-left: 5px;"
        "}"
        "QLabel:hover {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "               stop:0 #ff8e8e, stop:1 #08e6b0);"
        "}");

    logandregsiterbtn=new QPushButton();
    logandregsiterbtn->setText("登录");
    logandregsiterbtn->setFixedHeight(45);
    logandregsiterbtn->setStyleSheet(
        "QPushButton {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "               stop:0 #ff6b6b, stop:1 #06d6a0);"
        "   border: none;"
        "   border-radius: 22px;"
        "   color: white;"
        "   font-size: 16px;"
        "   font-weight: bold;"
        "}"
        "QPushButton:hover {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "               stop:0 #ff8e8e, stop:1 #08e6b0);"
        "}"
        "QPushButton:pressed {"
        "   background: qlineargradient(x1:0, y1:0, x2:1, y2:0,"
        "               stop:0 #ff4b4b, stop:1 #04c690);"
        "}");


    changeleftbtn=new QPushButton();
    changeleftbtn->setText("手机号登录");
    changeleftbtn->setFixedHeight(35);
    changeleftbtn->setStyleSheet(
        "QPushButton {"
        "   background: transparent;"
        "   border: 1px solid rgba(255, 255, 255, 0.3);"
        "   border-radius: 15px;"
        "   color: #a0a0a0;"
        "   font-size: 12px;"
        "   padding: 5px 10px;"
        "}"
        "QPushButton:hover {"
        "   background: rgba(255, 255, 255, 0.1);"
        "   color: #ffd166;"
        "   border: 1px solid rgba(255, 107, 107, 0.5);"
        "}"
        "QPushButton:pressed {"
        "   background: rgba(255, 255, 255, 0.2);"
        "}");



    changerightbtn=new QPushButton();
    changerightbtn->setText("注册");
    changerightbtn->setFixedHeight(35);
    changerightbtn->setStyleSheet(changeleftbtn->styleSheet());

    layout->addWidget(title,0,2,1,2,Qt::AlignTop);
    layout->addWidget(username,1,0,1,6,Qt::AlignTop);
    layout->addWidget(password,2,0,1,6,Qt::AlignTop);
    layout->addWidget(yanzhengcodeline,3,0,1,4,Qt::AlignTop);
    layout->addWidget(yanzhengcodelabel,3,4,1,2,Qt::AlignTop);

    layout->addWidget(logandregsiterbtn,4,0,1,6,Qt::AlignTop);
    layout->addWidget(changeleftbtn,5,0,1,2,Qt::AlignTop);
    layout->addWidget(changerightbtn,5,4,1,2,Qt::AlignTop);

    connect(changerightbtn,&QPushButton::clicked,this,[=](){

        if(changerightbtn->text()=="注册"&&changeleftbtn->text()=="手机号登录")
        {
            this->setWindowTitle("注册");
            title->setText("注册");
            changerightbtn->setText("登录");
            changeleftbtn->setText("手机号注册");
            logandregsiterbtn->setText("注册");
        }
        else if(changeleftbtn->text()=="手机号注册"&&changerightbtn->text()=="登录")
        {
             this->setWindowTitle("登录");
            title->setText("登录");
            changerightbtn->setText("注册");
            changeleftbtn->setText("手机号登录");
             logandregsiterbtn->setText("登录");
        }
        else if(changeleftbtn->text()=="切换到用户名"&&changerightbtn->text()=="注册")
        {
             this->setWindowTitle("登录");
            title->setText("注册");
            logandregsiterbtn->setText("注册");
            changerightbtn->setText("登录");
        }
        else if(changeleftbtn->text()=="切换到用户名"&&changerightbtn->text()=="登录")
        {
             this->setWindowTitle("注册");
            title->setText("登录");
            logandregsiterbtn->setText("登录");
            changerightbtn->setText("注册");
        }
    });

    connect(changeleftbtn,&QPushButton::clicked,this,[=](){
        if((changeleftbtn->text()=="手机号登录"&&changerightbtn->text()=="注册")||(changeleftbtn->text()=="手机号注册"&&changerightbtn->text()=="登录"))
        {
            username->setText("输入电话");
            yanzhengcodelabel->setText("发送验证码");
            password->hide();
            layout->removeWidget(password);
            changeleftbtn->setText("切换到用户名");
        }
        else if((changeleftbtn->text()=="切换到用户名"&&changerightbtn->text()=="注册")||(
                changeleftbtn->text()=="切换到用户名"&&changerightbtn->text()=="登录"))
        {

            username->setText("输入用户名");
            password->show();
            layout->addWidget(password,2,0,1,6,Qt::AlignTop);
            yanzhengcodelabel->setText("验证码");
            if(changerightbtn->text()=="登录")
                changeleftbtn->setText("手机号注册");
            else
            changeleftbtn->setText("手机号登录");
        }

    });



}
